package cn.xinfei.xdecision.common.service.component;

import cn.xinfei.xdecision.common.model.common.PageResult;
import cn.xinfei.xdecision.common.model.common.ResponseEntityDto;
import cn.xinfei.xdecision.common.model.component.ComponentVo;
import cn.xinfei.xdecision.common.model.component.dependency.resp.DecisionComponentDependencyResp;
import cn.xinfei.xdecision.common.model.component.guiderule.vo.RuleListReqVo;
import cn.xinfei.xdecision.common.utils.enums.enginex.ComponentTypeEnum;
import cn.xinfei.xdecision.common.utils.util.SpringContextUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 组件中心公共接口
 *
 * @author zdy
 */
public interface ComponentCommonService {

    /**
     * 查看组件是否有新建版本
     *
     * @param ruleCode 规则编码
     */
    Boolean hasNewVersion(String ruleCode);

    /**
     * 通过组件id集合查询组件信息和版本信息
     */
    List<ComponentVo> listComponentInfoByIds(String ids);

    /**
     * 通过变量code集合查询出所有组件code
     *
     * @param varCodes 变量code集合
     * @return 变量依赖关系返回值
     */
    List<DecisionComponentDependencyResp> getComponentCodeByVarCodes(List<String> varCodes);

    /**
     * 通过组件code集合批量查询变量信息
     *
     * @param componentVoList 组件code和versionNo集合
     * @return 变量返回值
     */
    List<String> getFieldCodesByComponentCodes(List<ComponentVo> componentVoList);

    /**
     * 通过关键字和文件夹id查询组件信息和版本信息
     *
     * @param ruleListReqVo 决策流组件通用查询入参
     * @return 组件及版本集合
     */
    List<ComponentVo> listComponentInfoByCon(RuleListReqVo ruleListReqVo);

    static ComponentCommonService getTargetComponentByType(String type) {
        ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.adapad(type);
        if (Objects.isNull(componentTypeEnum)) {
            return null;
        }
        return SpringContextUtil.getBeansOfType(ComponentCommonService.class)
                .getOrDefault(componentTypeEnum.getClassName(), null);
    }

    static ComponentCommonService getTargetComponentByNodeType(String nodeType) {
        ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.getByNodeType(nodeType);
        if (Objects.isNull(componentTypeEnum)) {
            return null;
        }
        return SpringContextUtil.getBeansOfType(ComponentCommonService.class)
                .getOrDefault(componentTypeEnum.getClassName(), null);
    }
}
